package com.gitee.wsl.mathematics.geometry.d2.circle

import com.gitee.wsl.mathematics.coordinate.d2.Coordinate2
import com.gitee.wsl.mathematics.geometry.api.CircleShape
import com.gitee.wsl.mathematics.geometry.d2.CloseShape2d
import com.gitee.wsl.mathematics.geometry.d2.PointShape2d
import com.gitee.wsl.mathematics.number.compareTo
import com.gitee.wsl.mathematics.vector.ext.minus
import com.gitee.wsl.unit.angle.AngleUnit
import kotlin.math.PI

interface CircleShape2d<N:Number,V: Coordinate2<N, V>>: CircleShape<N, V>,CloseShape2d<N,V>,PointShape2d<N,V> {

    val radiusSquared get() = radius * radius
    override val area get() = (PI * radius * radius)
    override val perimeter get() = (PI * 2.0 * radius)

    fun containsY(y: N): Boolean = abs(center.y - y) <radius
    fun containsX(x: N): Boolean = abs(center.x - x) <radius

    override fun containsPoint(p: Coordinate2<N, *>): Boolean = (p - center).length <= radius

    override fun distance(p: V): N = (p - center).length - radius
    override fun normalVectorAt(p: V) = (p - center).normalized

    fun createSegment(startAngle: AngleUnit, sweepAngle: AngleUnit):CircleSegment2d<N,V,*>

    fun create(p:V, radius:N):CircleShape2d<N,V>

    fun getPointOnAngle(angle: AngleUnit):V

}

